package com.devilvan.betrice.opgg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.opgg.dto.OpggPositionRoleDto;
import com.devilvan.betrice.opgg.po.OpggPositionRolePo;
import com.devilvan.betrice.opgg.service.OpggPositionRoleService;
import com.devilvan.betrice.opgg.mapper.OpggPositionRoleMapper;
import com.devilvan.betrice.opgg.repository.OpggPositionRoleRepository;
import com.devilvan.betrice.util.UCopy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Evad.Wu
 * @Description OPGG-英雄位置-角色定位信息 业务逻辑类
 * @date 2022-10-04
 */
@Service
public class OpggPositionRoleServiceImpl extends ServiceImpl<OpggPositionRoleMapper, OpggPositionRolePo> implements OpggPositionRoleService {
    @Resource(name = "opggPositionRoleRepository")
    private OpggPositionRoleRepository opggPositionRoleRepository;

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public OpggPositionRolePo saveUpdate(OpggPositionRoleDto opggPositionRoleDto) {
        OpggPositionRolePo opggPositionRolePo = new OpggPositionRolePo();
        UCopy.fullCopy(opggPositionRoleDto, opggPositionRolePo);
        return opggPositionRoleRepository.saveAndFlush(opggPositionRolePo);
    }

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public List<OpggPositionRolePo> saveUpdateBatch(List<OpggPositionRoleDto> list) {
        List<OpggPositionRolePo> opggPositionRolePoList = UCopy.fullCopyCollections(list, OpggPositionRolePo.class);
        return opggPositionRoleRepository.saveAllAndFlush(opggPositionRolePoList);
    }
}
